<template>
  <view>
    <web-view refs="wv" v-if="qwOauthVis" :src="src" class="webview" ></web-view>
  </view>
</template>

<script>

export default {
  data() {
    return {
      // title: '授权登录',
      qwOauthVis: false,
      openid: '',
      src:''
    }
  },

  props:{
      type:{
        type: String,
        default: 'redirectTo'
      },
    extParam:{
        type: String,
        default: ''
      },
    loginPage:{
      type: String,
      default: ''
    }
  },
   onReady() {
    // console.log(123)
    const openid = uni.getStorageSync('wx_oauth_openid')
    const openid_expire = uni.getStorageSync('wx_oauth_openid_expire')
    if (openid && openid_expire > Date.now()){
      this.openid = openid
      this.$emit('success-login',openid);
    }else{
      const page = getCurrentPages();
      const getOpenid = (page[page.length-1]?.options?.wechat_openid)
      // console.log(getCurrentPages())
      if (getOpenid){
        uni.setStorageSync('wx_oauth_openid', getOpenid)
        uni.setStorageSync('wx_oauth_openid_expire', Date.now()+(7200*2*1000))
        this.openid = getOpenid;
        this.$emit('success-login',getOpenid);
        // uni.setStorage('qw_oauth_openid')
      }else{
        //授权加载
        this.qwOauthVis = true
        this.src = `https://yzylive.vjike.cn/api/wx_oauth2/oauth2?login-page=${this.loginPage}&type=${this.type}&${this.extParam}`
      }
    }

  }
}
</script>

<style>
.webview{
  display: none;
  height: 300rpx;
  border: 1px solid #000;
}
.content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.logo {
  height: 200rpx;
  width: 200rpx;
  margin-top: 200rpx;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 50rpx;
}

.text-area {
  display: flex;
  justify-content: center;
}

.title {
  font-size: 36rpx;
  color: #8f8f94;
}
</style>
